package demo.niuke;


import java.util.Arrays;
import java.util.Scanner;

/**
 * @author : feixiang.li
 * @since : 2025-09-20 14:07
 */
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        while (T-- > 0) {
            int n = sc.nextInt();
            String s = sc.next();
            solve(n, s);
        }

    }

    public static void solve(int n, String s) {
        // 前面可以分隔出若干个相邻且不重叠的非空连续子串,且证分割后的子串序列按字典序不下降的前提下
        int[] dp = new int[n + 1];
        dp[0] = 1;
        dp[1] = 1;
        char[] str = s.toCharArray();

        int[][] lcp = new int[n + 1][n + 1];
        for (int i = n - 1; i >= 0; i--) {
            for (int j = n - 1; j >= 0; j--) {
                if (str[i] == str[j]) {
                    lcp[i][j] = lcp[i + 1][j + 1] + 1;
                } else {
                    lcp[i][j] = 0;
                }
            }
        }
        System.out.println();
    }

}
